package db.swing2;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.HierarchyBoundsAdapter;
import java.awt.event.HierarchyEvent;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.JEditorPane;
import java.awt.Dimension;
import javax.swing.JTextPane;
import java.awt.ComponentOrientation;
import java.awt.Font;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JCheckBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GUI extends JFrame {

	private JPanel contentPane;
	JFormattedTextField textFieldSearchTerm;
	final ButtonGroup buttonGroupType = new ButtonGroup();
	JTable tableHitList;
	JTextField textFieldIDN;
	JEditorPane editorPaneRecord;
	JScrollPane scrollPaneRecord;
	JButton btnIdnSearchID;
	JButton btnSearchName;
	JScrollPane scrollPaneHilList;
	JLabel labelStatus;
	JTextPane textPaneErrors;
	JLabel lblHitCount;
	JLabel labelRootName;
	JLabel labelRecordName;
	JTree treeOBB;
	JTree treeUBB;
	JScrollPane scrollPaneOB;
	JScrollPane scrollPaneUB;
	JSplitPane splitPaneOBUB;
	JSplitPane splitPaneHitRecord;
	JSplitPane splitPaneHitTree;
	JButton btnUBBExpanded;
	JButton btnOBExpanded;
	JPanel panelOBB;
	JPanel panelUBB;
	JLabel labelSearchTerm;
	JLabel lblUBCount;
	JLabel lbOBCount;

	/**
	 * Create the frame.
	 */
	public GUI() {
		setTitle("Hierarchische Darstellung von Schlagwörtern");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 1346, 628);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel panelSearch = new JPanel();
		contentPane.add(panelSearch, BorderLayout.NORTH);
		panelSearch.setLayout(new BoxLayout(panelSearch, BoxLayout.Y_AXIS));

		JPanel panelSearchName = new JPanel();
		FlowLayout fl_panelSearchName = (FlowLayout) panelSearchName
				.getLayout();
		fl_panelSearchName.setAlignment(FlowLayout.LEFT);
		panelSearch.add(panelSearchName);

		JLabel lblSuchbegriff = new JLabel("Suchbegriff: ");
		panelSearchName.add(lblSuchbegriff);

		textFieldSearchTerm = new JFormattedTextField();

		panelSearchName.add(textFieldSearchTerm);
		textFieldSearchTerm.setColumns(50);

		btnSearchName = new JButton("suchen ...");
		panelSearchName.add(btnSearchName);

		JLabel lblTyp = new JLabel("Typ: ");
		panelSearchName.add(lblTyp);

		JRadioButton rdbtnP = new JRadioButton("p");
		rdbtnP.setEnabled(false);
		panelSearchName.add(rdbtnP);
		buttonGroupType.add(rdbtnP);

		JRadioButton rdbtnB = new JRadioButton("b");
		panelSearchName.add(rdbtnB);
		buttonGroupType.add(rdbtnB);

		JRadioButton rdbtnF = new JRadioButton("f");
		rdbtnF.setEnabled(false);
		panelSearchName.add(rdbtnF);
		buttonGroupType.add(rdbtnF);

		JRadioButton rdbtnU = new JRadioButton("u");
		panelSearchName.add(rdbtnU);
		buttonGroupType.add(rdbtnU);

		JRadioButton rdbtnG = new JRadioButton("g");
		panelSearchName.add(rdbtnG);
		buttonGroupType.add(rdbtnG);

		JRadioButton rdbtnS = new JRadioButton("s");
		panelSearchName.add(rdbtnS);
		rdbtnS.setSelected(true);
		buttonGroupType.add(rdbtnS);

		JRadioButton rdbtnAllTypes = new JRadioButton("beliebig");
		panelSearchName.add(rdbtnAllTypes);
		buttonGroupType.add(rdbtnAllTypes);

		JPanel panelSearchID = new JPanel();
		FlowLayout fl_panelSearchID = (FlowLayout) panelSearchID.getLayout();
		fl_panelSearchID.setAlignment(FlowLayout.LEFT);
		panelSearch.add(panelSearchID);

		JLabel lblIdn = new JLabel("      oder idn: ");
		lblIdn.setHorizontalTextPosition(SwingConstants.LEFT);
		lblIdn.setHorizontalAlignment(SwingConstants.LEFT);
		panelSearchID.add(lblIdn);

		textFieldIDN = new JTextField();
		panelSearchID.add(textFieldIDN);
		textFieldIDN.setColumns(10);

		btnIdnSearchID = new JButton("Idn suchen");
		panelSearchID.add(btnIdnSearchID);

		splitPaneHitRecord = new JSplitPane();
		splitPaneHitRecord.setDividerSize(3);
		contentPane.add(splitPaneHitRecord, BorderLayout.CENTER);

		JPanel panelRecord = new JPanel();
		splitPaneHitRecord.setRightComponent(panelRecord);
		panelRecord.setLayout(new BorderLayout(0, 0));

		scrollPaneRecord = new JScrollPane();
		panelRecord.add(scrollPaneRecord, BorderLayout.CENTER);

		editorPaneRecord = new JEditorPane();
		editorPaneRecord.setContentType("text/html");
		editorPaneRecord.setEditable(false);
		scrollPaneRecord.setViewportView(editorPaneRecord);

		JPanel panelRecordInfo = new JPanel();
		scrollPaneRecord.setColumnHeaderView(panelRecordInfo);

		labelRecordName = new JLabel("");
		labelRecordName.setFont(new Font("Tahoma", Font.BOLD, 13));
		panelRecordInfo.add(labelRecordName);

		splitPaneHitTree = new JSplitPane();
		splitPaneHitTree.setDividerSize(3);
		splitPaneHitTree.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPaneHitRecord.setLeftComponent(splitPaneHitTree);

		JPanel panelHitList = new JPanel();
		splitPaneHitTree.setLeftComponent(panelHitList);
		panelHitList.setLayout(new BorderLayout(0, 0));

		JPanel panelHitListInfo = new JPanel();
		panelHitList.add(panelHitListInfo, BorderLayout.NORTH);

		JLabel lblTrefferlist = new JLabel("Trefferliste für:");
		panelHitListInfo.add(lblTrefferlist);
		
		labelSearchTerm = new JLabel("");
		panelHitListInfo.add(labelSearchTerm);
		
		JLabel lblZahlerDerTreffer = new JLabel(", Zahl der Treffer:");
		panelHitListInfo.add(lblZahlerDerTreffer);

		lblHitCount = new JLabel("");
		panelHitListInfo.add(lblHitCount);

		scrollPaneHilList = new JScrollPane();
		panelHitList.add(scrollPaneHilList);

		tableHitList = new JTable();
		tableHitList.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
			@Override
			public void ancestorResized(HierarchyEvent arg0) {
			}
		});
		tableHitList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		scrollPaneHilList.setViewportView(tableHitList);

		JPanel panelTree = new JPanel();
		splitPaneHitTree.setRightComponent(panelTree);
		panelTree.setLayout(new BorderLayout(0, 0));

		JPanel panelTreeInfo = new JPanel();
		panelTree.add(panelTreeInfo, BorderLayout.NORTH);

		labelRootName = new JLabel("");
		panelTreeInfo.add(labelRootName);

		splitPaneOBUB = new JSplitPane();
		splitPaneOBUB.setDividerSize(2);
		panelTree.add(splitPaneOBUB);

		panelOBB = new JPanel();
		splitPaneOBUB.setLeftComponent(panelOBB);
		panelOBB.setLayout(new BorderLayout(0, 0));

		scrollPaneOB = new JScrollPane();
		panelOBB.add(scrollPaneOB, BorderLayout.CENTER);

		treeOBB = new JTree();
		treeOBB.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		treeOBB.setModel(null);
		scrollPaneOB.setViewportView(treeOBB);

		JPanel panelOBInfo = new JPanel();
		scrollPaneOB.setColumnHeaderView(panelOBInfo);

		JLabel lblOb = new JLabel("OB-Baum  ");
		lblOb.setFont(new Font("Tahoma", Font.BOLD, 11));
		panelOBInfo.add(lblOb);

		btnOBExpanded = new JButton("+/-");
		panelOBInfo.add(btnOBExpanded);
		
		JLabel lblAnzahlEbene = new JLabel(" Anzahl 1. Ebene: ");
		panelOBInfo.add(lblAnzahlEbene);
		
		lbOBCount = new JLabel("");
		panelOBInfo.add(lbOBCount);

		panelUBB = new JPanel();
		splitPaneOBUB.setRightComponent(panelUBB);

		panelUBB.setLayout(new BorderLayout(0, 0));

		scrollPaneUB = new JScrollPane();
		panelUBB.add(scrollPaneUB, BorderLayout.CENTER);

		treeUBB = new JTree();
		treeUBB.setModel(null);
		scrollPaneUB.setViewportView(treeUBB);

		JPanel panelUBInfo = new JPanel();
		scrollPaneUB.setColumnHeaderView(panelUBInfo);

		JLabel lblUb = new JLabel("UB-Baum  ");
		lblUb.setFont(new Font("Tahoma", Font.BOLD, 11));
		panelUBInfo.add(lblUb);

		btnUBBExpanded = new JButton("+/-");
		btnUBBExpanded.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		panelUBInfo.add(btnUBBExpanded);
		
		JLabel lblAnzahlebene = new JLabel(" Anzahl 1. Ebene: ");
		panelUBInfo.add(lblAnzahlebene);
		
		lblUBCount = new JLabel("");
		panelUBInfo.add(lblUBCount);
		splitPaneOBUB.setDividerLocation(350);
		splitPaneHitTree.setDividerLocation(200);
		splitPaneHitRecord.setDividerLocation(750);

		JPanel panel = new JPanel();
		panel.setPreferredSize(new Dimension(10, 75));
		contentPane.add(panel, BorderLayout.SOUTH);
		panel.setLayout(new BorderLayout(0, 0));

		labelStatus = new JLabel(" Initialisiere Datenbank ...");
		panel.add(labelStatus, BorderLayout.SOUTH);

		JScrollPane scrollPaneErrors = new JScrollPane();
		panel.add(scrollPaneErrors);

		textPaneErrors = new JTextPane();
		scrollPaneErrors.setViewportView(textPaneErrors);

		JLabel lblFehlermeldungen = new JLabel("Fehlermeldungen:");
		lblFehlermeldungen.setHorizontalAlignment(SwingConstants.CENTER);
		scrollPaneErrors.setColumnHeaderView(lblFehlermeldungen);

	}

}
